<?php
include 'su_log.php';
include '../inc/d.php';
//删除
if (isset($_GET['did']) && isset($_GET['filename'])) {
    deleteById('hw_zizhi', $_GET['did']);
    unlink('../upload/zizhi/' . $_GET['filename']);
    header('location:zizhi_manager.php');
}
//修改checkbox是否显示
if(isset($_GET['zizhi_id']) && isset($_GET['zizhi_flag'])){
    updateByPID('hw_zizhi',$_GET);
    header('location:zizhi_manager.php');
}
$rows = query('hw_zizhi');
?>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>admin</title>
    <script src="../js/jquery-3.1.1.min.js"></script>
    <style>
        .tb{
            border-collapse: collapse;
            margin:0 auto;
        }
        .tb tr td,.tb tr th{
            padding:8px;
            border:1px solid gray;
        }

        .yes{
            opacity: 1;
        }

        .no{
            opacity: .5;
        }
    </style>
</head>
<body>
	<table class="tb">
		<tr>
			<th>ID</th>
			<th>资质名称</th>
			<th>资质文件</th>
			<th>资质图片</th>
			<th>发布时间</th>
			<th>是否显示</th>
			<th>基本操作</th>
		</tr>	    
	    <?php foreach($rows as $value) { ?>
        <tr>
            <td><?=$value['zizhi_id']?></td>
            <td>
                <!--修改 资质名称-->
                <?php if(isset($_GET['uid']) && $value['zizhi_id']==$_GET['uid']){ ?>
                    <form action="zizhi_updatesave.php" method="post">
                        <input type="hidden" name="zizhi_id" value="<?=$value['zizhi_id']?>">
                        <input type="text" name="zizhi_name" value="<?=$value['zizhi_name']?>">
                        <input type="submit" value="保存">
                    </form>
                <?php }else{ ?>
                    <?=$value['zizhi_name']?>
                <?php } ?>
            </td>
            <td><?=$value['zizhi_filename']?></td>
            <td><img width="50" src="../upload/zizhi/<?=$value['zizhi_filename']?>"></td>
            <td><?=date('Y-m-d H:i:s',$value['zizhi_time'])?></td>
            <td>
                <?php if($value['zizhi_flag']=='y'){?>
                    <label class="yes"><input type="checkbox" onclick="location.href='?zizhi_id=<?=$value['zizhi_id']?>&zizhi_flag=n'" checked>显示</label>
                <?php }else{ ?>
                    <label class="no"><input type="checkbox" onclick="location.href='?zizhi_id=<?=$value['zizhi_id']?>&zizhi_flag=y'" >显示</label>
                <?php } ?>
            </td>
            <td>
            	<a href="?did=<?=$value['zizhi_id']?>&filename=<?=$value['zizhi_filename']?>">删除</a>&nbsp;
                <a href="?uid=<?=$value['zizhi_id']?>">编辑</a>&nbsp;
            </td>
        </tr>
        <?php } ?>
	    <tr>
	        <td colspan="7"><a href="zizhi_add.html">添加新资质</a></td>
	    </tr>
	</table>
</body>
</html>